﻿CREATE PROCEDURE [dbo].[SponsorTypeAllowedParent_InsertUpdate]

	@id						BIGINT,

	@sponsorTypeId			BIGINT,

	@parentSponsorTypeId	BIGINT,

	@modifiedId				VARCHAR (0060)

AS

	BEGIN 

		MERGE SponsorTypeAllowedParent

			USING (SELECT @id) AS Source (Id)

				ON SponsorTypeAllowedParent.Id = Source.Id

			WHEN MATCHED THEN 

				UPDATE SET 

					ParentSponsorTypeId = @parentSponsorTypeId,

					ModifiedId = @modifiedId,

					ModifiedDateTime = GETDATE ()

			WHEN NOT MATCHED THEN 

				INSERT (SponsorTypeId, ParentSponsorTypeId, CreateId, CreateDateTime, ModifiedId, ModifiedDateTime) 

					VALUES (@sponsorTypeId, @parentSponsorTypeId, @modifiedId, GETDATE (), @modifiedId, GETDATE())

		; -- MERGE ( END )


	END

	